package 蓝桥算法;

import java.util.Arrays;

public class day09 {
    public char[] reserveString(char[] s){
        int j=s.length-1;
        int i=0;
        while(i<j){
            s[i]^=s[j];
            s[j]^=s[i];
            s[i]^=s[j];//完成俩数组值的交互
            i++;
            j--;
        }
        return s;
    }
    public String reserveString(String s,int k){
        char[] ch=s.toCharArray();
        for (int i = 0; i <ch.length;i+=2*k){
            int start=i;
            int end=Math.min(ch.length-1,start+k-1);
            while(start<end){
                ch[start]^=ch[end];
                ch[end]^=ch[start];
                ch[start]^=ch[end];
                start++;
                end--;
            }
        }
            return new String(ch);
    }

    public static void main(String[] args) {
      day09 a=new day09();
      char[] s={'a','d','f','g','h','j'};
      char[] x=a.reserveString(s);
        for (int i = 0; i < x.length; i++) {
            System.out.println(x[i]);
        }
    }
}
